package com.huaxin.hxmoduleworkorder.common.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;
import com.huaxin.hxmoduleworkorder.common.enums.base.BaseCodeEnum;

/**
 * 检查项类别枚举
 */
public enum InspectionTemplateItemCategory implements BaseCodeEnum {
    ELECTRICAL_SAFETY("electrical_safety", "电气安全"),
    EQUIPMENT_OPERATION("equipment_operation", "设备运行"),
    ENVIRONMENTAL_INSPECTION("environmental_inspection", "环境检查");

    @EnumValue
    private final String code;
    private final String displayName;

    InspectionTemplateItemCategory(String code, String displayName) {
        this.code = code;
        this.displayName = displayName;
    }

    @JsonValue
    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getDisplayName() {
        return displayName;
    }

    /**
     * 根据 code 获取枚举值
     */
    public static InspectionTemplateItemCategory of(String code) {
        for (InspectionTemplateItemCategory category : values()) {
            if (category.getCode().equalsIgnoreCase(code)) {
                return category;
            }
        }
        return null;
    }

    /**
     * 验证 code 是否有效
     */
    public static boolean isValid(String code) {
        return of(code) != null;
    }
}
